package com.yylending.las.lending;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.content.Loader;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import com.yyfax.infrastructure.eventbus.EventAgent;
import com.yyfax.infrastructure.mvp.Presenter;
import com.yylending.las.Constants;
import com.yylending.las.R;
import com.yylending.las.base.BaseFragment;
import com.yylending.las.common.widgets.RedDotView;
import com.yylending.las.common.widgets.TelephoneTextView;
import com.yylending.las.lending.outlet.OutletActivity;
import com.yylending.las.main.MainController;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

/**
 * 强制提额-门店查询
 * Created by laixj on 2018/1/10.
 * Copyright ©2016 www.yylending.com. All Rights Reserved.
 */

public class LowQuotaOutletSearchFragment extends BaseFragment {

	static final String TAG = LowQuotaOutletSearchFragment.class.getSimpleName();
	@BindView(R.id.red_dot_view)
	RedDotView mRedDotView;
	@BindView(R.id.outlet_search_btn)
	Button mOutletSearchBtn;
	@BindView(R.id.service_phone_tv)
	TelephoneTextView mServicePhoneTv;
	Unbinder unbinder;
	@BindView(R.id.title_left_iv)
	ImageView mTitleLeftIv;
	@BindView(R.id.title_tv)
	TextView mTitleTv;
	@BindView(R.id.title_right_tv)
	TextView mTitleRightTv;
	@BindView(R.id.title_right_iv)
	ImageView mTitleRightIv;

	public static BaseFragment newInstance() {
		BaseFragment fragment = new LowQuotaOutletSearchFragment();
		Bundle args = new Bundle();
		fragment.setArguments(args);
		return fragment;
	}

	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);
	}

	@Override
	public void onDetach() {
		super.onDetach();
	}

	@Override
	public void onStart() {
		super.onStart();
	}

	@Override
	public void onStop() {
		super.onStop();
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View rootView = inflater.inflate(R.layout.view_low_quota_outlet_search, container, false);
		unbinder = ButterKnife.bind(this, rootView);
		initView();
		return rootView;
	}

	private void initView() {
		mTitleLeftIv.setImageResource(R.drawable.ic_home_help);
		mTitleTv.setText(R.string.tab_lend);
		mTitleRightIv.setImageResource(R.drawable.ic_message_white);
		mServicePhoneTv.setPageNo(Constants.PAGE_NO_MAIN_ACTIVITY);
		MainController.initRedDot(mRedDotView);
	}

	@Override
	public void onLoadFinished(Loader<Presenter> loader, Presenter data, int placeholder) {
		switch (loader.getId()) {
			default:
				break;
		}
	}

	@Override
	public Loader<Presenter> onCreateLoader(int id, Bundle args) {
		switch (id) {
			default:
				return null;
		}
	}

	@OnClick({R.id.title_left_iv, R.id.title_right_iv, R.id.outlet_search_btn})
	public void onViewClicked(View view) {
		switch (view.getId()) {
			case R.id.title_left_iv:
				EventAgent.post(new QuotaEvent.PageJumpEvent(QuotaEvent.PageJumpEvent.QUOTA_JUMP_HELP_PAGE, Constants.PAGE_NO_MAIN_ACTIVITY));
				break;
			case R.id.title_right_iv:
				EventAgent.post(new QuotaEvent.PageJumpEvent(QuotaEvent.PageJumpEvent.QUOTA_JUMP_MESSAGE_PAGE, Constants.PAGE_NO_MAIN_ACTIVITY));
				MainController.hideRedDot(mRedDotView);
				break;
			case R.id.outlet_search_btn:
				OutletActivity.start(getActivity());
				break;
		}
	}

	@Override
	public void onDestroyView() {
		super.onDestroyView();
		unbinder.unbind();
	}

	@Subscribe(threadMode = ThreadMode.MAIN)
	public void onRedDotShowEvent(QuotaEvent.ShowRedDotEvent event) {
		mRedDotView.setVisibility(View.VISIBLE);
	}
}